home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TNetworkStream.h < prev   
Encoding:
Text File  |  1996-01-11  |  2.7 KB  |  107 lines  |  [TEXT/CWIE]

  1. //    TNetworkStream.h - Macintosh OpenTransport Network Stream IO class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #ifndef _H_TNETWORKSTREAM
  18. #define _H_TNETWORKSTREAM
  19.  
  20. #include <iostream.h>
  21. #include <OpenTransport.h>
  22. #include "TCachedStorage.h"
  23. #include "TList.h"
  24.  
  25. //
  26. // TNetworkBuf  - Macintosh OpenTransport Network Stream Buffer class object
  27. //
  28.  
  29. #define BUFFSIZE 128
  30.  
  31. class TNetworkBuf :  public streambuf {
  32.  
  33. //     CONSTRUCTORS AND DESTRUCTORS
  34. public:
  35.         TNetworkBuf() : streambuf(),
  36.                         fEndPoint(kOTInvalidRef),
  37.                         fBuffer(nil),
  38.                         fChunkSize(0) { };
  39.         ~TNetworkBuf();
  40.         
  41. // HIGH LEVEL FUNCTIONS
  42. public:
  43.     void    attach (EndpointRef ep, TEndpointInfo* info);
  44.     void    close();
  45.     int        is_open() const { return (fEndPoint != (EndpointRef)kOTInvalidRef) ; }
  46.  
  47. // CLASS MEMBERS
  48. public:
  49.     static     void    Release(void *);
  50.     
  51.             char*    ReserveBuffer(size_t reqCount, size_t  *actCount);
  52.             void    EnqueueBuffer(char* buf, size_t count);
  53.             
  54.  
  55. // PROTECTED FUNCTIONS
  56. protected :
  57.     virtual int     overflow( int = EOF);
  58.     virtual int     sync();
  59.     virtual int     xsputn( const char*, int);
  60.     
  61.     virtual int     underflow();
  62.     virtual int     uflow();
  63.         
  64. // PRIVATE FUNCTIONS
  65. private:    
  66.             int        flush_output(OTFlags flags = 0);
  67.         Boolean        doallocate();
  68.  
  69. // PRIVATE FIELDS
  70. private:
  71.     EndpointRef        fEndPoint;            // network endpoint
  72.     TEndpointInfo*     fInfo;                // pointer to endpoint Info Stucture
  73.     char*            fBuffer;            // begining of buffer area
  74.     size_t            fChunkSize;            // default chunksize
  75.     
  76.     char            Buffer[BUFFSIZE];
  77. };
  78.  
  79. //
  80. // TNetworkOStream  - Macintosh OpenTransport Network Stream output class object
  81. //
  82.  
  83. class TNetworkIOStream :  
  84.                     virtual public TNetworkBuf, 
  85.                     virtual public ostream, 
  86.                     virtual public istream {
  87.  
  88. //     CONSTRUCTORS AND DESTRUCTORS
  89.     public:
  90.         TNetworkIOStream (): 
  91.                             ostream((TNetworkBuf*) this),
  92.                             istream((TNetworkBuf*) this),
  93.                             ios(0) {};
  94.                             
  95.         TNetworkIOStream (EndpointRef ep, TEndpointInfo* info):
  96.                                  ostream((TNetworkBuf*) this),
  97.                                  istream((TNetworkBuf*) this),
  98.                                  ios(0) 
  99.                                  { attach(ep, info); };
  100.    ~TNetworkIOStream();
  101.  
  102. };
  103.  
  104.  
  105.  
  106. #endif
  107.